package demo3;

import java.util.Objects;

class Preson{
    public String name;
    public int age;

    public Preson(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Preson{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if(o == null){
            return false;
        }
        if(this == o){
            return true;
        }
        if(!(o instanceof Preson)) {
            return false;
        }
        Preson preson = (Preson) o;
        return this.age==preson.age && this.name.equals(preson.name);
    }
}
public class Test {
    public static void main(String[] args) {
        Preson preson1 = new Preson("张三", 18);
        System.out.println(preson1);
        Preson preson2 = new Preson("张三", 18);
        System.out.println(preson2);
        System.out.println("==========================");
        System.out.println(preson1 == preson2);
        System.out.println(preson1.equals(preson2));

    }
}
